﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WarningForeverClone.src.weapons;

namespace WarningForeverClone.src.util
{
    public class Pool<T> where T : new()
    {
        Stack<T> items;
        public Pool()
        {
            items = new Stack<T>();
        }
        public Pool(int initialAmount)
        {
            items = new Stack<T>();
            for (int x = 0; x < initialAmount; x++)
            {
                items.Push(new T());
            }
        }

        public T Get()
        {
            if (items.Count > 0)
                return items.Pop();
            else
                return new T();
        }

        public void Free(T item)
        {
            items.Push(item);
        }

    }
}
